package crudfx.navigation;
import javax.swing.*;
import java.awt.*;
import javax.swing.tree.*;
/**
 * @profile desktop
 * @author Sergey Surikov
 */
public class TreeLeaf extends TreeItem{
    public var text:String;
    public var icon:Icon;
    override var tooltip="TreeLeaf";
    public var action:function():Void;
    var renderer:DefaultTreeCellRenderer;
    init{
        renderer=DefaultTreeCellRenderer{
            override public function getBackground():Color{
                return null;
                }
            override public function getBackgroundNonSelectionColor():Color{
                return null;
                }
            };
        if(icon!=null)renderer.setLeafIcon(icon);
        onSelect=function():Boolean{
            action();
            return false;
            }
        }
    override public function add(tree:Tree,parent:DefaultMutableTreeNode):Void{
        tree.add(parent, this);
        }
    override public function getCellComponent(tree:JTree,value:Object
                                    ,selected:Boolean,expanded:Boolean
                                    ,leaf:Boolean,row:Integer
                                    ,hasFocus:Boolean):Component{
        var c=renderer.getTreeCellRendererComponent(tree,text
                                                ,selected,expanded,true,row
                                                ,hasFocus);
        return c;
        }
    }
